package com.youi.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.youi.common.Common;
import com.youi.common.DelStatus;
import com.youi.dao.ActivitygoodsDao;
import com.youi.entity.Activitygoods;
import com.youi.entity.Goods;
import com.youi.entity.Goodssize;
import com.youi.entity.Purchasehistory;
import com.youi.entity.User;
import com.youi.service.ActivitygoodsService;
import com.youi.service.GoodsService;
import com.youi.service.GoodssizeService;
import com.youi.service.PurchasehistoryService;

@Service
public class ActivitygoodsServiceImpl extends BaseServiceImpl<Activitygoods> implements ActivitygoodsService{
		
		private ActivitygoodsDao activitygoodsDao;
		@Autowired
		private GoodsService goodsService;
		@Autowired
		private GoodssizeService goodssizeService;
		@Autowired
		private PurchasehistoryService purchasehistoryService;
		@Autowired
		public void setfaultRecordDao(ActivitygoodsDao activitygoodsDao){
			this.activitygoodsDao=activitygoodsDao;
			super.setBaseDAO(activitygoodsDao);
		}

		@Override
		public void getGoodsMsg(List<Activitygoods> activitygoodsList) {
			// TODO Auto-generated method stub
			if (activitygoodsList!=null&&activitygoodsList.size()>0) {
				for (Activitygoods activitygoods : activitygoodsList) {
					Map<String, Object> params=new HashMap<String, Object>();
					params.put(Common.DELSTATUS, DelStatus.NODEL);
					params.put(Common.ID, activitygoods.getGoodsId());
					Goods goods=goodsService.getByParam(params);
					Integer realSaleCnt=0; 
					Integer allStockNum=0;
					Double salePrice=0.00;
					Double marketPrice=0.00;
					Integer saleNum=0;
					if (goods!=null) {
						realSaleCnt=goods.getRealSaleCnt();
						allStockNum=goods.getRealStockCnt();
						params=new HashMap<String, Object>();
						params.put(Common.DELSTATUS, DelStatus.NODEL);
						params.put("goodsId", activitygoods.getGoodsId());
						List<Goodssize> goodssizeList=goodssizeService.getByParams(params);
						Goodssize goodssize=goodssizeList.get(0);
						salePrice=goodssize.getPrice();
						marketPrice=goods.getEcPrice();
					}					
					activitygoods.setRealSaleCnt(realSaleCnt);
					activitygoods.setAllStockNum(allStockNum);
					activitygoods.setSalePrice(salePrice);
					activitygoods.setMarketPrice(marketPrice);
					activitygoods.setSaleNum(saleNum);
				}
			}
		}
}